<template>
  <div class="refuse-modal">
    <a-modal
      :visible="isShowRefuseModel"
      unmount-on-close
      :render-to-body="false"
      :mask-closable="false"
      :closable="false"
      :mask="false"
      title-align="start"
      @ok="handelConfirmRefuse"
      @cancel="handleCancelRefuse(false)"
    >
      <template #title>
        <div class="refuse-modal__title">拒绝原因</div>
      </template>
      <a-textarea v-model="refuseContent" placeholder="请输入" :auto-size="{ minRows: 5 }" allow-clear />
      <template #footer>
        <div class="buttons">
          <a-button class="cancel-button" type="secondary" @click="handleCancelRefuse(false)">取消</a-button>
          <a-button class="confirm-button" type="primary" @click="handelConfirmRefuse">确认拒绝</a-button>
        </div>
      </template>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { Message } from "@arco-design/web-vue";
import { workbenchMsgHandle } from "@/apis";
import type { AttachmentsListItem, MsgConfirmParams } from "@/apis";

const props = defineProps({
  modelValue: Boolean,
  msgId: String,
  fileList: Array as () => AttachmentsListItem[]
});
const emit = defineEmits(["update:modelValue", "confirm", "cancel"]);
const isShowRefuseModel = computed({
  get: () => props.modelValue,
  set: val => emit("update:modelValue", val)
});

const isHandleMsgLoading = ref(false);
const refuseContent = ref("");
const handelConfirmRefuse = async () => {
  try {
    isHandleMsgLoading.value = true;
    const postData = {
      msgId: props.msgId,
      status: 5,
      opinionInfo: refuseContent.value,
      resourceUrls: props.fileList
    };
    await workbenchMsgHandle(postData as MsgConfirmParams);
    Message.success("操作成功");
    isHandleMsgLoading.value = false;
    handleCancelRefuse(true);
  } catch (err) {
    isHandleMsgLoading.value = false;
  }
};
const handleCancelRefuse = (isRefresh: boolean) => {
  refuseContent.value = "";
  emit("cancel", isRefresh);
};
</script>

<style scoped lang="scss">
@import "refuseModel";
</style>
